<?php
namespace app\admin\controller;

use think\Db;

/**
 * 前台栏目页面展示
 * Class SolutionController
 * @package app\admin\controller
 */
class BlockController extends CommonController
{
    //首页设置
    public function index()
    {
        if (request()->isPost()) {
            $data = input('post.');
            $str = serialize($data);
            //dump($str);
            $rs = Db::name('block')->where('type','index')->update(['content' => $str]);
            if ($rs === false) {
                $this->error('修改失败，请稍后重试');
            }else {
                $this->success('修改成功');
            }
        }
        //获取首页区块内容
        $content = Db::name('block')->field('content')->where('type', 'index')->find();
        //反序列化 数据
        $data = unserialize($content['content']);

        $this->assign('data', $data);
        return $this->fetch();
    }
    //2.公司简介
    public function gsjj()
    {
        if (request()->isPost()) {
            $data = input('post.');
            $str = serialize($data);
            //dump($str);
            $rs = Db::name('block')->where('type','gsjj')->update(['content' => $str]);
            if ($rs === false) {
                $this->error('修改失败，请稍后重试');
            }else {
                $this->success('修改成功');
            }
        }
        //获取首页区块内容
        $content = Db::name('block')->field('content')->where('type', 'gsjj')->find();
        //反序列化 数据
        $data = unserialize($content['content']);

        $this->assign('data', $data);
        return $this->fetch();
    }
    //3.产品中心
    public function chanpin()
    {
        //获取父级类的内容
        $data = $this->common_block('chanpin');
        if (request()->isPost()) {
            if ($data === false) {
                $this->error('修改失败，请稍后重试');
            }else {
                $this->success('修改成功');
            }
        }
        $this->assign('data', $data);
        return $this->fetch();
    }
    //4. 招聘中心
    public function news()
    {
        //获取父级类的内容
        $data = $this->common_block('news');
        if (request()->isPost()) {
            if ($data === false) {
                $this->error('修改失败，请稍后重试');
            }else {
                $this->success('修改成功');
            }
        }

        $this->assign('data', $data);
        return $this->fetch();
    }

    //删除
    public function delete()
    {
        $id = input('post.id/d');
        $data = ['errno' => 1, 'msg' => '删除失败'];
        if (  Db::name('product')->where('id', $id)->delete() ) { //删除成功
            $data = ['errno' => 0, 'msg' => '删除成功'];
        }
        return $data;
    }
}
